package ariman.pact.consumer.DSLpact;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class DSLPactProviderService {
    private String backendURL = "http://localhost:8080/register";
    public String getBackendURL() {
        return this.backendURL;
    }

    public void setBackendURL(String URLBase) {
        this.backendURL = URLBase+"/register";
    }

    public DSLpactDto getDSLpactDto(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        String params = "{\"username\": \"张三\",\"password\":\"123456\",\"verifyCode\":1234}";
        HttpEntity formString = new HttpEntity(params,headers);
        DSLpactDto dsLpactDto =  restTemplate.postForObject(getBackendURL(),formString,DSLpactDto.class);
        return dsLpactDto;
    }
}
